//
//  ReweetedStatusView.swift
//  SinaWeibo
//
//  Created by 周小伟 on 16/8/25.
//  Copyright © 2016年 周小伟. All rights reserved.
//转发微博

import UIKit
import SnapKit

class ReweetedStatusView: UIView {

    var bottomConstraints:Constraint?
    
    var retweetedStatus:Status?{
        didSet{
            retweetedLabel.text = retweetedStatus?.text
            
            self.bottomConstraints?.uninstall()
            if let picurls = retweetedStatus?.imageURLs where picurls.count > 0{
                pictureView.imageURLs = picurls
                pictureView.hidden = false
                
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomConstraints = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                })
            }else{
                pictureView.hidden = true
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomConstraints = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin).constraint
                })
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addSubview(retweetedLabel)
        addSubview(pictureView)
        
        retweetedLabel.snp_makeConstraints { (make) in
            make.top.equalTo(snp_top).offset(StatusCellMargin)
            make.left.equalTo(snp_left).offset(StatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
        }
        
        self.snp_makeConstraints { (make) in
            self.bottomConstraints = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    }
    private lazy var retweetedLabel = UILabel(title: "我是转发微博", size: 14, color: UIColor.darkGrayColor(),margin: StatusCellMargin)
    
    private lazy var pictureView:StatusPictureView = StatusPictureView()
}
